package com.invest.intergration;

import com.invest.config.AppProperties;
import com.invest.infra.constants.AppConstants;
import com.invest.utils.rest.RestClientUtils;
import com.invest.utils.rest.RestTemplateFactory;
import com.invest.utils.security.SignUtils;
import com.invest.utils.uuid.IdWorker;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by evan on 2016/7/28.
 */
@Service
public class WxsClient {
    private static final Logger LOGGER = LoggerFactory.getLogger(WxsClient.class);
    @Autowired
    private AppProperties appProperties;

    public void bindCategory(String crpId,String mobile,String interviewCompany){

        try {
            if(StringUtils.isBlank(mobile) || StringUtils.isBlank(interviewCompany)){
                return ;
            }
            String uri = appProperties.getWxsHost() + "/news/category/bind/"+ crpId;
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("mobile", mobile);
            map.put("newsCategory", interviewCompany);
            String forObject = RestTemplateFactory.instance().postForObject(uri, RestClientUtils.buildJsonBody(map), String.class);
            LOGGER.info("crp={} mobile={} interviewCompany={} 绑定结果={} ",crpId,mobile,interviewCompany,forObject);
        }catch (Throwable ex){
            LOGGER.error("crp={} mobile={} interviewCompany={} 绑定失败 ",crpId,mobile,interviewCompany,ex);
        }

    }

}
